xl: Add basic bash completion for xl command.
authorKeir Fraser <keir.fraser@citrix.com>
Tue, 4 May 2010 10:48:10 +0000 (11:48 +0100)
committerKeir Fraser <keir.fraser@citrix.com>
Tue, 4 May 2010 10:48:10 +0000 (11:48 +0100)
Signed-off-by: Yang Hongyang <yanghy@cn.fujitsu.com>
Config.mk
tools/libxl/Makefile
tools/libxl/bash-completion [new file with mode: 0644]

index 2a0030ce4ccf0652ff294d03187567ef0eea4d77..7fe691fed4f118f996b3c971979941ec20ee61b7 100644 (file)
--- a/Config.mk
+++ b/Config.mk
@@ -29,6 +29,7 @@ include $(XEN_ROOT)/config/$(XEN_TARGET_ARCH).mk
 SHAREDIR    ?= $(PREFIX)/share
 DOCDIR      ?= $(SHAREDIR)/doc/xen
 MANDIR      ?= $(SHAREDIR)/man
+BASH_COMPLETION_DIR ?= /etc/profile.d
 
 ifneq ($(EXTRA_PREFIX),)
 EXTRA_INCLUDES += $(EXTRA_PREFIX)/include
index f79bc42abe155e2e19507f60fb4a0fba847a1dea..4ecbc19e608aca2b5d611db34168dacc256bebd2 100644 (file)
@@ -100,6 +100,7 @@ install: all
        ln -sf libxlutil.so.$(XLUMAJOR) $(DESTDIR)$(LIBDIR)/libxlutil.so
        $(INSTALL_DATA) libxlutil.a $(DESTDIR)$(LIBDIR)
        $(INSTALL_DATA) libxl.h $(DESTDIR)$(INCLUDEDIR)
+       $(INSTALL_DATA) bash-completion $(BASH_COMPLETION_DIR)/xl.sh
 
 .PHONY: clean
 clean:
diff --git a/tools/libxl/bash-completion b/tools/libxl/bash-completion
new file mode 100644 (file)
index 0000000..4b870e6
--- /dev/null
@@ -0,0 +1,21 @@
+#!/bin/bash
+# Copy this file to /etc/profile.d/xl.sh
+
+_xl()
+{
+       local IFS=$'\n,'
+
+       local cur opts xl
+       COMPREPLY=()
+       cur="${COMP_WORDS[COMP_CWORD]}"
+       xl=xl
+       
+       if [[ $COMP_CWORD == 1 ]] ; then
+               opts=`${xl} help 2>/dev/null | sed 'n;d' | sed '1,2d' | awk '{print $1}' | sed 's/$/ ,/g'` && COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
+               return 0
+       fi
+
+       return 0
+}
+
+complete -F _xl -o nospace -o default xl